package com.yzy.domain.entity.system;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;

@Getter
@Setter
public class BaseEntity {
    private static final String DELETED_INIT_STATUS = "0";

    private static final String DELETED_STATUS = "1, deleted_on = (SELECT CURRENT_TIMESTAMP(3))";

    @TableId(type = IdType.UUID)
    private String id;

    @TableField(fill = FieldFill.INSERT)
    private String createdBy;

    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createdOn;

    @TableField(fill = FieldFill.UPDATE)
    private String updatedBy;

    @TableField(fill = FieldFill.UPDATE)
    private LocalDateTime updatedOn;

    @TableLogic(value = DELETED_INIT_STATUS, delval = DELETED_STATUS)
    private Boolean deleted;

    private LocalDateTime deletedOn;

    @TableField(fill = FieldFill.DEFAULT)
    private String deletedBy;

    @TableField(fill = FieldFill.INSERT)
    private Boolean disabled;

    @Version
    @TableField(fill = FieldFill.INSERT_UPDATE, update = "%s+1")
    private Long version;

    public BaseEntity() {
        createdOn = LocalDateTime.now();
        version = 1L;
        deleted = false;
        disabled = false;
    }
}